package org.ssm.footstep.util;

import java.awt.Frame;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

import javax.swing.JOptionPane;

public class Utility {
	private static Properties properties = new Properties();
	
	public static void loadProperties() {
		File file = new File("FootStep.ini");
		properties = new Properties();
		if(file.exists()) {
			try {
				properties.load(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void saveProperties() {
		File file = new File("FootStep.ini");
		if(file.exists()) {
			file.delete();
		}
		
		try {
			properties.store(new FileWriter(file), "");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static boolean isEmpty(String arg) {
		if(arg != null && arg.length() > 0) { 
			return false;
		}
		
		return true;
	}
	
	public static String getProperty(String key, String defValue) {
		String value = properties.getProperty(key);
		
		if(Utility.isEmpty(value)) {
			return defValue;
		}
		
		return value;
	}
	
	public static void setProperty(String key, String value) {
		properties.setProperty(key, value);
	}
	
	public static void Log(String message) {
		//System.out.print(message + "\n");
	}
	
	public static void showMessageDialog(Frame f, String message) {
		JOptionPane.showMessageDialog(f, message);
	}
}
